package securityproject.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

public class Constants {

	private static final String WEB_BASE = "webapps/SecurityProject/";
	// private static final String WEB_BASE = "WebContent/";

	private static String PROPS_FILE = WEB_BASE + "properties/constants.props";

	public static String XSL_BASE_WEB_FOLDER = WEB_BASE + "xslt/";

	// public static String BASE_FOLDER =
	// "C:/eclipseProjects/securityProject/files/";
//	public static String BASE_FOLDER = "C:/Documents and Settings/myatsina/Desktop/studies/semester 9/security project/workspace/files/";
	 public static String BASE_FOLDER = "E:/SecurityProject/files/";

	public final static String LOG_FOLDER = BASE_FOLDER + "logs/";

	public final static String TEMP_FOLDER = BASE_FOLDER + "temporaryFiles/";

	public final static String XSL_PREFIX_RULES_FILE = BASE_FOLDER
			+ "XSLRules/prefixRules/wireshark-basic-v3.xslt";

	public final static String XSL_FILTER_RULES_FOLDER = BASE_FOLDER
			+ "XSLRules/filterRules/";

	public final static String XML_RULES_FOLDER = BASE_FOLDER
			+ "XSLRules/xmlRules/";

	public final static String XSL_ACTIVE_FOLDER = "active/";

	public final static String XSL_INACTIVE_FOLDER = "inactive/";

	public final static String XSL_RULE_NOT_DISMISSED_UNKNOWN = "tor-to-html-v3-included-unknown.xslt";

	public final static String XSL_RULE_NOT_DISMISSED_ONLY = "tor-to-html-v3-included-only.xslt";

	public final static String XSL_RULE_UNKNOWN_ONLY = "tor-to-html-v3-unknown-only.xslt";

	public final static String XML_RULES_TRANSFORMER = XSL_BASE_WEB_FOLDER
			+ "ruleTransformer.xslt";

	public final static String XML_RULES_PRESENTER = XSL_BASE_WEB_FOLDER
			+ "rulePresenter.xslt";

	public final static String XML_NEW_RULE = XSL_BASE_WEB_FOLDER
			+ "newRule.xml";

	private static String XSL_SUFFIX_RULE_FILE = XSL_RULE_UNKNOWN_ONLY;

	public static String getXSLSuffixRule() {
		return XSL_SUFFIX_RULE_FILE;
	}
	
	public static String getXSLSuffixRuleFile() {
		return XSL_BASE_WEB_FOLDER + XSL_SUFFIX_RULE_FILE;
	}

	public static void setXSLSuffixRuleFile(String suffixRule) {
		XSL_SUFFIX_RULE_FILE = suffixRule;

		props.setProperty("XSL_SUFFIX_RULE_FILE", XSL_SUFFIX_RULE_FILE);

		try {
			FileOutputStream propFile = new FileOutputStream(PROPS_FILE);
			props.storeToXML(propFile, "");
			propFile.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static Properties props;

	public static void init() {
		XSL_SUFFIX_RULE_FILE = XSL_RULE_UNKNOWN_ONLY;

		props = new Properties();

		try {

			FileInputStream propsFile = new FileInputStream(PROPS_FILE);
			props.loadFromXML(propsFile);
			propsFile.close();

		} catch (InvalidPropertiesFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// BASE_FOLDER = props.getProperty("BASE_FOLDER");
		// XSL_BASE_WEB_FOLDER = props.getProperty("BASE_WEB_FOLDER");
		XSL_SUFFIX_RULE_FILE = props.getProperty("XSL_SUFFIX_RULE_FILE");
	}

}
